package com.cardrive.engine;

import java.util.Timer;
import java.util.TimerTask;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;

import com.cardrive.entity.Car;
import com.cardrive.entity.Engine;

public class GameEngine extends View {

	private static final int FPS = 24;
	private Car car;
	private Context context;

	private Paint paint;
	private Timer timer;

	public GameEngine(Context context) {
		super(context);
		this.context = context;
		init();
	}

	private void init() {
		car = new Car(context, new Engine(), 50, 50);
		paint = new Paint();

		timer = new Timer();

		timer.schedule(new TimerTask() {

			@Override
			public void run() {
				postInvalidate();
			}
		}, 1000, 1000/FPS);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);

		if (car != null)
			car.render(canvas, paint);

	}

	public Car getCar() {
		return car;
	}

	public void setCar(Car car) {
		this.car = car;
	}

}
